package com.twu.biblioteca.options;

import com.twu.biblioteca.Option;
import com.twu.biblioteca.UserInterface;
import com.twu.biblioteca.UserRepository;

public class LogInOption implements Option {
    private final UserInterface ui;
    private final UserRepository userRepository;

    public LogInOption(UserInterface ui, UserRepository userRepository) {
        this.ui = ui;
        this.userRepository = userRepository;
    }

    @Override
    public void Execute() {
        String userLibraryNumber = ui.getLibraryNumber();
        String password = ui.getPassword();
        boolean wasAuthenticated = this.userRepository.authenticateUser(userLibraryNumber, password);

        if (wasAuthenticated) {
            this.ui.showMessage("Credentials correct. You have been logged in");
        }
        else {
            this.ui.showMessage("Incorrect credentials entered. You have not been logged in.");
        }
    }

    @Override
    public String toString() {
        return "Login";
    }
}
